<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
        <!-- <el-form-item label="产品编码" prop="roleName">
          <el-input
            v-model="queryParams.roleName"
            placeholder="请输入产品编码"
            clearable
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
        <el-form-item label="生产时间"></el-form-item>
          <el-date-picker
            v-model="dateRange"
            style="width: 340px"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetimerange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="qualifiedList">
        <!-- <el-table-column type="selection" width="55" align="center" /> -->
        <el-table-column label="序号" type="index" width="50"/>
        <el-table-column label="产品编码" prop="productCode" :show-overflow-tooltip="true" width="auto" />
        <!-- <el-table-column label="开始时间" prop="roleKey" :show-overflow-tooltip="true" width="150" />
        <el-table-column label="结束时间" prop="roleKey" :show-overflow-tooltip="true" width="150" /> -->
        <el-table-column label="生产数量" prop="totalCount" :show-overflow-tooltip="true" width="auto" />
        <el-table-column label="不合格数量" prop="unqualifiedCount" :show-overflow-tooltip="true" width="auto" />
        <el-table-column label="合格数量" prop="qualifiedCount" :show-overflow-tooltip="true" width="auto" />
        <el-table-column label="合格率" prop="qualifiedRate" :show-overflow-tooltip="true" width="auto" />

        <!-- <el-table-column label="状态" align="center" width="100">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.status"
              active-value="0"
              inactive-value="1"
              @change="handleStatusChange(scope.row)"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope" v-if="scope.row.roleId !== 1">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['system:role:edit']"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system:role:remove']"
            >删除</el-button>
            <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)" v-hasPermi="['system:role:edit']">
              <el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="handleDataScope" icon="el-icon-circle-check"
                  v-hasPermi="['system:role:edit']">数据权限</el-dropdown-item>
                <el-dropdown-item command="handleAuthUser" icon="el-icon-user"
                  v-hasPermi="['system:role:edit']">分配用户</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column> -->
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </template>

  <script>
  import { ProductQualifiedQuery } from "@/api/system/datamanage"
  import moment from 'moment'

  export default {
    name: "Passreate",
    // dicts: ['alarm_type'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 角色表格数据
        qualifiedList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 日期范围
        dateRange: ['', ''],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10
        },
        // 表单参数
        form: {}
      };
    },
    created() {
      let startTime = moment().subtract(1, 'month').format('YYYY-MM-DD') +' 00:00:00';
      let endTime = this.parseTime(new Date());
      this.dateRange = [startTime,endTime]
      this.getList();
    },
    methods: {
      /** 查询生产合格率列表 */
      async getList() {
        this.loading = true;
        let params = JSON.parse(JSON.stringify(this.queryParams))
        await ProductQualifiedQuery(this.addDateTimeRange(this.queryParams,this.dateRange)).then(response => {
            this.qualifiedList = response.rows;
            this.total =  response.total;
            this.loading = false;
          }
        );
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      }
    }
  };
  </script>
